package cn.knight.controller;

import cn.knight.User;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RefreshScope
@RestController
public class UserCtrl {

    @Value("${test}")
    private Long test;

    @GetMapping("/user/{id}")
    @SentinelResource(value = "user", blockHandler = "exceptionHandler")
    public User loadById(@PathVariable Long id){
        return new User().setId(test).setName("不重要").setIntro("你不管嘛");
    }


    public User exceptionHandler(@PathVariable Long id, BlockException ex){
        ex.printStackTrace();
        return new User().setId(-1L).setName("爬开哦").setIntro("你G了~~~~");
    }

}
